/*
Source : https://leetcode.com/problems/reverse-integer/
Author : nflush@outlook.com
Date   : 2016-05-06
*/

/*
283. Move Zeroes  
Total Accepted: 79019 Total Submissions: 178436 Difficulty: Easy

Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.

For example, given nums = [0, 1, 0, 3, 12], after calling your function, nums should be [1, 3, 12, 0, 0].

Note:

    You must do this in-place without making a copy of the array.
    Minimize the total number of operations.

Credits:
Special thanks to @jianchao.li.fighter for adding this problem and creating all test cases.

Subscribe to see which companies asked this question
*/

void moveZeroes(int* nums, int numsSize) {
    int *pR = nums;
    int *pW = nums;
    int i, z = 0;
    for(i = 0; i< numsSize; i++){
        if (*pR == 0){
            z++;
            pR++;
        } else {
            *pW++ = *pR++;
        }
    }
    for(i = 0; i< z; i++){
        *pW++ = 0;
    }
}

void moveZeroes(int* nums, int numsSize) {
    int *pR = nums;
    int *pW = nums;
    int i, z = 0;
    for(i = 0; i< numsSize && nums[i]; i++);
    pR = pW = &nums[i];

    for(; i< numsSize; i++){
        if (*pR == 0){
            z++;
            pR++;
        } else {
            *pW++ = *pR++;
        }
    }
    for(i = 0; i< z; i++){
        *pW++ = 0;
    }
}